package com.talent.web.excel;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

/**
 * @ClassName：GenderCoverter
 * @Author: hszhou
 * @Date: 2024/11/16 13:27
 * @Description: 必须描述类做什么事情, 实现什么功能
 */
public class GenderConverter implements Converter<Integer> {
    @Override
    public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {


        String stringValue = cellData.getStringValue();
        return GenderEnum.getCodeByLabel(stringValue);

    }

//    @Override
//    public WriteCellData<?> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
//
//        String labelByCode = GenderEnum.getLabelByCode(value);
//        return
//    }


    public enum  GenderEnum{


        MALE(0,"男"),
        FEMALE(1,"女"),
        SECRET(2,"保密")
        ;
        private Integer code;

        private String label;

        public Integer getCode() {
            return code;
        }

        public void setCode(Integer code) {
            this.code = code;
        }

        public String getLabel() {
            return label;
        }

        public void setLabel(String label) {
            this.label = label;
        }

        GenderEnum(int code, String label){
            this.code =code;
            this.label = label;
        }

        public static Integer getCodeByLabel(String label){

            for (GenderEnum value : GenderEnum.values()) {
                if(value.getLabel().equals(label)){
                    return value.getCode();
                }
            }
            return 0;
        }

        public static String getLabelByCode(int code){

            for (GenderEnum value : GenderEnum.values()) {
                if(value.getCode()==code){
                    return value.getLabel();
                }
            }
            return "男";
        }


    }
}
